function Validate(object) {
  var obj = object

  this.effDateCheck = function(rule, value, callback) {
    // console.log('checkEffectiveDate')
    if (value === null || value === '') {
      return callback()
    }
    if (!obj.phase.operationEndDate) {
      return callback()
    }
    var effectiveDate = new Date(obj.phase.effDate)
    var expirationDate = new Date(obj.phase.operationEndDate)
    if (effectiveDate.getTime() > expirationDate.getTime()) {
      return callback(new Error('生效日期不能大于操作截止日期'))
    }
    return callback()
  }

  this.operationEndDateCheck = function(rule, value, callback) {
    // console.log('checkExpirationDate')
    if (value === null || value === '') {
      return callback()
    }
    var effectiveDate = new Date(obj.phase.effDate)
    var expirationDate = new Date(obj.phase.operationEndDate)
    if (effectiveDate.getTime() > expirationDate.getTime()) {
      return callback(new Error('操作截止日期不能小于生效日期'))
    }
    return callback()
  }

  this.validate = function() {
    var error = []
    for (var name in obj.phase) {
      var method = name + 'Check'
      if (typeof (this[method]) === 'function') {
        this[method](null, obj.phase[name], (res) => {
          if (res) {
            error.push(res.message)
          }
        })
      }
    }
    return error
  }
}
export default Validate
